﻿using MediatR;
using TaskProject.Application.Command.Production;
using TaskProject.Domain.Production;
using TaskProject.ErrorCode;
using TaskProject.InfrasIntructure.Interface;

namespace TaskProject.Application.Handler.Production
{
    public class GetProductProcessHandler : IRequestHandler<GetProductProcessCommand, APIResult<ProductProcessModel>>
    {
        IBaseRepository<ProductProcessModel> processRepo;

        public GetProductProcessHandler(IBaseRepository<ProductProcessModel> processRepo)
        {
            this.processRepo = processRepo;
        }

        public Task<APIResult<ProductProcessModel>> Handle(GetProductProcessCommand request, CancellationToken cancellationToken)
        {
            APIResult<ProductProcessModel> res=new APIResult<ProductProcessModel>();
            var pros = processRepo.GetAll().Where(c => c.WorkOrderId == request.WorkOrderId).FirstOrDefault();
            res.Msg = "查询工序成功";
            res.Data = pros;
            res.Code = APIEnum.Success;
            return Task.FromResult(res);
        }
    }
}
